package com.maolong.workqueues;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class WorkProductor {
    private static final String QUEUE_NAME = "work_queue";
    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("182.92.151.172");
        factory.setUsername("maolong");
        factory.setPassword("123456");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);
        System.out.println("[producter] send message to queue: " + QUEUE_NAME);

        for (int i=0;i<10;i++){
            String message = "hello world"+i;
            channel.basicPublish("",QUEUE_NAME,null,message.getBytes());
        }
        channel.close();
        connection.close();
    }
}
